﻿using System.Net;
using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Https;

namespace WebCoreAdmin
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();

        /// <summary>
        /// https
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                   .UseKestrel(opt =>
                               {
                                   opt.Listen(IPAddress.Any, 443, op =>
                                                                  {
                                                                      var ada = new HttpsConnectionAdapterOptions();
                                                                      ada.ServerCertificate          = new X509Certificate2("D:\\tmp\\localhost.pfx", "wshy89");
                                                                      ada.CheckCertificateRevocation = true;
                                                                      ada.ClientCertificateMode      = ClientCertificateMode.RequireCertificate;
                                                                      ada.ClientCertificateValidation = (certificate2, chain, arg3) =>
                                                                                                        {
                                                                                                            return true;
                                                                                                        };
                                                                      op.UseHttps(ada);
                                                                  });
                               })
                   .UseStartup<Startup>()
                   .UseUrls("https://*:443")
                   .Build();
    }

}

